package com.hnhs.controller;

import com.hnhs.model.Product;
import com.hnhs.model.ProductQuery;
import com.hnhs.model.ProductStatusUpdate;
import com.hnhs.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/product")
//@CrossOrigin //开启跨域访问  原始的axios 并未封装的
public class ProductController {
    @Autowired
    private ProductService service;


    @GetMapping
    public List<Product> select(ProductQuery query){

        List<Product> selectlist = service.select(query);
        return selectlist;
    }
    @PostMapping
    public int insert(@RequestBody Product product){
        return service.insert(product);
    }
    @PutMapping
    public int update(@RequestBody Product product){
        return service.update(product);
    }
    @DeleteMapping
    public int delete(Integer id){
        return service.delete(id);
    }

    @PatchMapping
    public int updateStatus(@RequestBody ProductStatusUpdate update){
        return  service.updateStatus(update);
    }


}
